package com.fh.modules.kms.service.impl;

/**
 * @Author qiujunda
 * @Date 20/05/2020
 * @Description
 */
//@Service("elasticService")
public class ElasticServiceImpl /*implements IElasticService */
{
   /* @Autowired
    private ElasticsearchRestTemplate elasticsearchTemplate;
    @Autowired
    private ElasticRepository elasticRepository;

    private Pageable pageable = PageRequest.of(0,10);

    @Override
    public void createIndex() {
        elasticsearchTemplate.createIndex(Knowledge.class);
    }

    @Override
    public void deleteIndex(String index) {
        elasticsearchTemplate.deleteIndex(index);
    }

    @Override
    public void save(Knowledge docBean) {
        elasticRepository.save(docBean);
    }

    @Override
    public void saveAll(List<Knowledge> list) {
        elasticRepository.saveAll(list);
    }

    @Override
    public Iterator<Knowledge> findAll() {
        return elasticRepository.findAll().iterator();
    }

    @Override
    public Page<Knowledge> queryForPage(){
        //排序
        SortBuilder sortBuilder1 = SortBuilders.fieldSort("createTime").order(SortOrder.DESC);
        //分页
        PageRequest pageable = PageRequest.of(1,20);
        NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
                .withQuery(QueryBuilders.termQuery("content", "啊")).withSort(sortBuilder1).withPageable(pageable)
                .build();
        return elasticsearchTemplate.queryForPage(searchQuery,Knowledge.class);
    }

    @Override
    public Object queryAggregationForPage(){
        TermsAggregationBuilder agg = AggregationBuilders.terms("asd").field("createBy.keyword");
        SearchQuery searchQuery = new NativeSearchQueryBuilder()
                .withQuery(QueryBuilders.termQuery("content", "啊")).addAggregation(agg).withPageable(PageRequest.of(0, 1))
                .build();
        AggregatedPage<Knowledge> testEntities =elasticsearchTemplate.queryForPage(searchQuery,Knowledge.class);
//        Terms terms = (Terms)propertyInfoEntities.getAggregation("聚合名称，之前自定义的");
        return testEntities;
    }*/


}
